{% extends 'main/base.html' %}
{% load gtlink_tags %}
{% block head %}
    <script type="text/javascript">
        $(document).ready(function () {
            loadPasswordChangeForm();
            $("#pw_change_container").on("submit", "form", function () {
                $.post($(this).attr("action"), $(this).serialize(), function (result) {
                    loadPasswordChangeForm(result);
                });
                return false;
            });
        });

        function loadPasswordChangeForm(html) {
            var cnt = $("#pw_change_container");
            cnt.fadeOut(function () {
                if (typeof html == 'undefined')
                    cnt.load("/password");
                else if (html == 'OK') {
                    cnt.html("Пароль успешно изменен!");
                    setTimeout(loadPasswordChangeForm, 5000);
                }
                else
                    cnt.html(html);
            });
            cnt.fadeIn();
        }
    </script>
{% endblock %}
{% block content %}
    <h2>Информация о клиенте</h2>
    <table class="client_form">
        {% for field in client_form %}
            <tr>
                <td>{{ field.label_tag }}</td>
                <td>
                    {% with field_type=field|get_type %}
                        {% if field_type == 'choice' %}
                            {{ field|render_choice }}
                        {% elif field_type == 'boolean' %}
                            {{ field.value|yesno:"Да,Нет" }}
                        {% elif field.value %}
                            {{ field.value }}{% endif %}</td>
                    {% endwith %}
            </tr>
        {% endfor %}
    </table>
    <fieldset>
        <legend>Сменить пароль</legend>
        <div id="pw_change_container" style="display: none"/>
    </fieldset>
{% endblock %}